//
//  MyOrderCell.m
//  jiyujiaProgram
//
//  Created by Jame on 15/11/22.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "MyOrderCell.h"
#import "MyOrderModel.h"

@implementation CALayer (Additions)

- (void)setBorderColorFromUIColor:(UIColor *)color
{
    self.borderColor = color.CGColor;
}
@end

@implementation MyOrderCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setCellWithModel:(NSArray *)model WithIndexPath:(NSIndexPath *)indexPath WithSegment:(NSInteger)segment
{
    MyOrderData *data = model[indexPath.section];
    if ([data.mName length]) {
        self.nameLabel.text = data.mName;
    }
    else{
        self.nameLabel.text = @"暂无";
    }
    self.titleLabel.text = data.course_name;
    self.typeLabel.text = data.have_class_way;
    
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:data.mImageUrl] placeholderImage:ECIMAGENAME(@"header.png")];

    NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
    [timeFormatter setDateFormat:@"HH:mm"];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *date = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[data.class_time integerValue]/1000]];
    NSString *start = [timeFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[data.class_time integerValue]/1000]];
    NSString *end = [timeFormatter stringFromDate:[NSDate dateWithTimeInterval:60*60 sinceDate:[NSDate dateWithTimeIntervalSince1970:[data.class_time integerValue]/1000]]];
    NSString *dateString = [NSString stringWithFormat:@"%@   %@-%@",date,start,end];
    self.classTimeLabel.text = dateString;
    self.priceLabel.text = [NSString stringWithFormat:@"%@/元",data.price];
    self.courseTimeLabel.text = data.period;
    self.cheapLabel.text = data.couponName;
    self.orderIdLabel.text = data.order_no;
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *orderTime = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[data.class_time integerValue]/1000]];
    self.orderTimeLabel.text = orderTime;
    self.payMoneyLabel.text = [NSString stringWithFormat:@"￥%@",data.total_price];
    
    switch (segment) {
        case 0:
        {
            self.payTypeLabel.text = @"待付款";
            self.payTypeLabel.hidden = NO;
            self.payMoneyLabel.hidden = NO;
            self.commentButton.hidden = YES;
            self.payButton.hidden=NO;
            self.cancelButton.hidden=NO;
        }
            break;
        case 1:
        {
            self.payTypeLabel.text = @"已付款";
            self.payTypeLabel.hidden = NO;
            self.payMoneyLabel.hidden = NO;
            self.commentButton.hidden = YES;
            self.payButton.hidden=YES;
            self.cancelButton.hidden=YES;

        }
            break;
        case 2:
        {
            self.payTypeLabel.hidden = YES;
            self.payMoneyLabel.hidden = YES;
            self.commentButton.hidden = YES;
            self.payButton.hidden=YES;
            self.cancelButton.hidden=YES;

        }
            break;
        case 3:
        {
            self.commentButton.hidden = NO;
            self.payTypeLabel.hidden = YES;
            self.payMoneyLabel.hidden = YES;
            self.payButton.hidden=YES;
            self.cancelButton.hidden=YES;

        }
            break;

        default:
            break;
    }
}

- (IBAction)payClick:(id)sender {
    if ([self.delegate respondsToSelector:@selector(myOrderCell:payClick:)]) {
        [self.delegate myOrderCell:self payClick:sender];
    }
}


- (IBAction)commentClick:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(myOrderCell:commentClick:)]) {
        [self.delegate myOrderCell:self commentClick:sender];
    }
}


- (IBAction)chatClick:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(myOrderCell:chatClick:)]) {
        [self.delegate myOrderCell:self chatClick:sender];
    }
}

- (IBAction)cancelClick:(id)sender {
    if ([self.delegate respondsToSelector:@selector(myOrderCell:cancelClick:)]) {
        [self.delegate myOrderCell:self cancelClick:sender];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
